/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actioncombination.dao;


import actioncombination.logic.agent.action.Action;
import java.util.List;

/**
 *
 * @author N
 */
public class ActionDAO
        extends GenericHibernateDAO<Action, Integer>
        implements IActionDAO {

    private ITransactionStrategy transaction = null;

    public ActionDAO() {
        transaction = new DefaultTransactionStrategy();
    }

    @Override
    public List<Action> findByExample(Action exampleInstance) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void saveOrUpdate(Action action) {
        try {
            transaction.beginTransaction();
            this.makePersistent(action);
            transaction.commit();

        } catch (RuntimeException e) {
            transaction.rollback();
            throw e; // or display error message
        }
    }

    public void delete(Action action) {
        try {
            transaction.beginTransaction();
            this.makeTransient(action);
            transaction.commit();

        } catch (RuntimeException e) {
            transaction.rollback();
            throw e; // or display error message
        }
    }

    public void setTransactionStrategy(ITransactionStrategy strategy) {
        transaction = strategy;
    }
}
